# -*- coding: utf-8 -*-
# @Time    : 2019/10/21 17:01
# @Author  : 岳保保
# @File    : CustomException.py
# @Software: PyCharm
import json

from django.http import JsonResponse


class CustomException(Exception):
    """
    基础异常类
    """

    def __init__(self, success=False, code=11111, msg='操作失败!', data=None):
        self.success = success
        self.code = code
        self.msg = msg
        self.data = data

    @property
    def response(self):
        return JsonResponse({
            "success": self.success,
            "code": self.code,
            "message": self.msg,
            "data": self.data
        }, safe=False, json_dumps_params={'ensure_ascii': False})
